package com.moon.game.server;

import java.util.concurrent.ConcurrentHashMap;

import org.jboss.netty.channel.Channel;

import com.moon.game.client.UdpClientSet;
import com.moon.game.message.ObjMessage;

public class NetServer {
	private static ConcurrentHashMap<String, DataSession> dataSessions = new ConcurrentHashMap<String, DataSession>();
	private static ConcurrentHashMap<String, ObjMessage> responseMsgs = new ConcurrentHashMap<String, ObjMessage>();
	public static void handleRequest(Channel channel, ObjMessage data) {
		DataSession session = new DataSession(data, channel);
		dataSessions.put(data.getSid(), session);
		UdpClientSet.send2AppServer(data);
	}
	
	/**
	 * 获取Session数据
	 * @param playerId
	 * @return
	 */
	public static DataSession getDataSession(String sid){
		return dataSessions.get(sid);
	}
	
	/**
	 * 删除
	 */
	public static void removeDataSession(String sid){
		dataSessions.remove(sid);
	}

	public static ConcurrentHashMap<String, DataSession> getDataSessions(){
		return dataSessions;
	}	
	
	/**
	 * 是否达到最大请求
	 * @return
	 */
	public static boolean isMaxRequest(){
		return dataSessions.size()>=(160) ? true:false; 
	}
	
	public static int getReqSessionSize(){
		return dataSessions.size();
	} 
	
	/**
	 * 添加应答数据
	 * @param response
	 */
	public static void addResponseMsg(ObjMessage response){
		responseMsgs.put(response.getSid(), response);
	}
	/**
	 * 获取并移除数据
	 * @param playerId
	 * @return
	 */
	public static ObjMessage getResponseMsg(String sid){
		return responseMsgs.remove(sid);
	}
}
